package cn.edu.zjgsu.ito.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class GetTime {

	static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	/**
	 * 获取系统现在时间
	 * 
	 * @return
	 */
	public static Date getNowTime() {
		String dateStr = sdf.format(new Date());
		Date date = null;
		try {
			date = sdf.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return date;
	}

	/**
	 * string ---> date yyyy-MM-dd HH:mm:ss
	 * 
	 * @param source
	 * @return
	 */
	public static Date strToDate(String source) {
		Date date = null;
		try {
			date = sdf.parse(source);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return date;
	}
	
	
	public static String dateToStr(Date date){
		String dateStr = sdf.format(date);
		return dateStr;
	}

}
